package com.xyzwps.paimon.furina.modules.post.entity

import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.dao.id.LongIdTable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.kotlin.datetime.datetime

data class PostCollection(
    val id: Long,
    val userId: Long,
    val title: String,
    val createTime: LocalDateTime,
    val deleteTime: LocalDateTime?,
    val updateTime: LocalDateTime
) {

    constructor(row: ResultRow) : this(
        id = row[TABLE.id].value,
        userId = row[TABLE.userId],
        title = row[TABLE.title],
        createTime = row[TABLE.createTime],
        deleteTime = row[TABLE.deleteTime],
        updateTime = row[TABLE.updateTime],
    )

    companion object {
        const val TITLE_MAX_LEN = 120

        object TABLE : LongIdTable("post_collection", columnName = "id") {
            val userId: Column<Long> = long("user_id")
            val title: Column<String> = varchar("title", TITLE_MAX_LEN)
            val createTime: Column<LocalDateTime> = datetime("create_time")
            val deleteTime: Column<LocalDateTime?> = datetime("delete_time").nullable()
            val updateTime: Column<LocalDateTime> = datetime("update_time")
        }
    }
}
